package demo.android.com.mvpdemo.mvp3.base;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import demo.android.com.mvpdemo.mvp3.proxy.ActivityMvpProxy;
import demo.android.com.mvpdemo.mvp3.proxy.ActivityMvpProxyImpl;

/**
 * Created by Vya on 2018/1/4 0004.
 */

public abstract class BaseMvpActivity extends AppCompatActivity implements BaseView {
    private ActivityMvpProxy mMvpProxy;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setViewContent();
        Log.e("wangyan","BaseMvpActivity---->");
        //创建  P,每个子类的P都不一样要交给子类创建


        mMvpProxy = createMvpProxy();
        mMvpProxy.bindAndCreatePresenter();
        initView();
        initData();
    }

    private ActivityMvpProxy createMvpProxy() {
        if(mMvpProxy == null){
            mMvpProxy = new ActivityMvpProxyImpl<>(this);
        }
        return mMvpProxy;
    }


    protected abstract void setViewContent();
    protected abstract void initView();
    protected abstract void initData();
   // protected abstract P createPresenter();


    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMvpProxy.unbindPresenter();
    }

//    public P getPresenter() {
//        return mPresenter;
//    }
}
